//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Configuration;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity;
using EntLibContrib.Query.Configuration.Unity;
using EntLibContrib.Query.Queries;

namespace EntLibContrib.Query.Configuration
{
	/// <summary>
	/// Configuration information for DataQueryData. This class represents the extra information, over and
	/// above what is defined in <see cref="QueryData" />, needed to connect resource to the Data block.
	/// </summary>
	[Assembler(typeof(DataQueryAssembler))]
	[ContainerPolicyCreator(typeof(DataQueryPolicyCreator))]
	public class DataQueryData : QueryData
	{
		#region Constants
		private const string databaseInstanceNameProperty = "databaseInstanceName";
		private const string commandProperty = "command";
		private const string commandTypeProperty = "commandType";
		#endregion

		#region Properties
		/// <summary>
		/// Name of the database instance to use for the data source. The Instance must be defined in Data configuration.
		/// </summary>
		[ConfigurationProperty(databaseInstanceNameProperty, IsRequired = true)]
		public string DatabaseInstanceName
		{
			get { return (string)base[databaseInstanceNameProperty]; }
			set { base[databaseInstanceNameProperty] = value; }
		}

		/// <summary>
		/// Name of the data command to use. This can be a Stored Procedure name or a SQL query string.
		/// </summary>
		[ConfigurationProperty(commandProperty, IsRequired = true)]
		public string Command
		{
			get { return (string)base[commandProperty]; }
			set { base[commandProperty] = value; }
		}

		/// <summary>
		/// Type of data command to use. This can be a stored procedure or text.
		/// </summary>
		[ConfigurationProperty(commandTypeProperty, IsRequired = true)]
		public CommandType CommandType
		{
			get { return (CommandType)base[commandTypeProperty]; }
			set { base[commandTypeProperty] = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="DataQueryData"/> class.
		/// </summary>
		/// <overloads>
		/// Initializes an instance of a <see cref="DataQueryData"/> class.
		/// </overloads>
		public DataQueryData()
		{
		}

		/// <summary>
		/// Initialize a new instance of the <see cref="DataQueryData"/> class.
		/// </summary>
		/// <param name="name">The name of the <see cref="DataQueryData"/>.</param>
		/// <param name="customCommandName">Name of the custom command.</param>
		/// <param name="parameterSetName">Name of the parameter set.</param>
		/// <param name="databaseInstanceName">Name of the database instance to use for the data source. Instance must be defined in Data configuration.</param>
		/// <param name="command">The command.</param>
		/// <param name="commandType">Type of the command.</param>
		public DataQueryData(string name, string customCommandName, string parameterSetName, string databaseInstanceName, string command, CommandType commandType)
			: base(name, typeof(DataQuery), customCommandName, parameterSetName)
		{
			this.DatabaseInstanceName = databaseInstanceName;
			this.Command = command;
			this.CommandType = commandType;
		}
		#endregion
	}
}